<template>
  <div>
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-col :span="11">
          <el-form-item label="sql1" prop="sql1">
            <el-input v-model="formData.sql1" type="textarea" placeholder="请输入sql1" rows="15" style="weight:75%;"
                      :autosize="{minRows: 15, maxRows: 150}" :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="sql2" prop="sql2">
            <el-input v-model="formData.sql2" type="textarea" placeholder="请输入sql2" rows="15" style="weight:75%;"
                      :autosize="{minRows: 15, maxRows: 150}" :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="生成类别" prop="type">
            <el-radio-group v-model="formData.type" size="medium">
              <el-radio v-for="(item, index) in typeOptions" :key="index" :label="item.value"
                        :disabled="item.disabled">{{item.label}}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item>
            <el-button size="medium" type="primary" @click="submitForm">提交</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
    import {mapGetters} from 'vuex'
    import {getToken} from '@/utils/auth'
    import checkPermission from '@/utils/permission'
    import initData from '@/mixins/initData'
    import {parseTime, downloadFile} from '@/utils/index'
    import {compareDifferentFromSql} from '@/api/code-tools'
    import {downloadFileFunction} from '@/api/downloadFile'
    export default {
        components: {},
        props: [],
        data() {
            return {
                formData: {
                    sql1: '',
                    sql2: '',
                    type: 'sql1'
                },
                rules: {
                    sql: [{
                        required: true,
                        message: '请输入sql1',
                        trigger: 'blur'
                    }],
                    sql2: [{
                        required: true,
                        message: '请输入sql2',
                        trigger: 'blur'
                    }],
                },
                typeOptions: [{
                    "label": "以sql1为基准",
                    "value": "sql1"
                }, {
                    "label": "以sql2为基准",
                    "value": "sql2"
                }],
            }
        },
        computed: {},
        watch: {},
        created() {
        },
        mounted() {
        },
        methods: {
            submitForm() {
                this.$refs['elForm'].validate(valid => {
                    if (!valid) return
                    const sql1 = this.formData.sql1;
                    const sql2 = this.formData.sql2;
                    const type = this.formData.type;
                    let params = {
                        sql1: sql1,
                        sql2: sql2,
                        type: type
                    }
                    let outputFileName = `两个sql` + `比较结果.xlsx`;
                    compareDifferentFromSql(params).then(res => {
                        downloadFileFunction(res, outputFileName)
                        this.$notify({
                            title: '文件处理成功',
                            type: 'success',
                            duration: 2500
                        })
                    }).catch(err => {
                        console.log(err);
                    });
                })
            },
            resetForm() {
                this.$refs['elForm'].resetFields()
            },
        }
    }

</script>
<style>
</style>
